package com.jingdianjichi.interview.server.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingdianjichi.interview.api.vo.InterviewQuestionHistoryVO;
import com.jingdianjichi.interview.api.vo.InterviewVO;
import com.jingdianjichi.interview.server.entity.po.InterviewQuestionHistory;
import com.jingdianjichi.interview.server.mapper.InterviewQuestionHistoryDao;
import com.jingdianjichi.interview.server.service.InterviewQuestionHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName:interviewQuestionHistoryServiceImpl
 * Package:com.jingdianjichi.interview.server.service.Impl
 * Description:
 *
 * @Author fst
 * @Create 2025/2/25 14:24
 * @Version 1.0
 */
@Service("interviewQuestionHistoryService")
public class interviewQuestionHistoryServiceImpl extends ServiceImpl<InterviewQuestionHistoryDao, InterviewQuestionHistory> implements InterviewQuestionHistoryService
{
    @Override
    public List<InterviewQuestionHistoryVO> detail(Long id)
    {
        LambdaQueryWrapper<InterviewQuestionHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InterviewQuestionHistory::getInterviewId, id).
                eq(InterviewQuestionHistory::getIsDeleted, 0);

        List<InterviewQuestionHistory> list = super.list(queryWrapper);

        List<InterviewQuestionHistoryVO> result = new ArrayList<>();

        if(CollectionUtils.isEmpty(list))
        {
            return result;
        }

        list.forEach(item->
        {
            InterviewQuestionHistoryVO vo = new InterviewQuestionHistoryVO();
            vo.setKeyWords(item.getKeyWords());
            vo.setQuestion(item.getQuestion());
            vo.setAnswer(item.getAnswer());
            vo.setScore(item.getScore());
            vo.setUserAnswer(item.getUserAnswer());
            result.add(vo);
        });
        return result;
    }
}
